/*
vuex:使用
1：导入vuex
2:注册Vuex (Vue.use)
3:实例化
4:暴露出去
5:在main.js的new Vue中挂载

vuex持久化
vuex-persistedstate
1:下载  npm i vuex-persistedstate
2：导入  import persistedstate  from 'vuex-persistedstate'
3:配制
  plugins:[
    persistedstate({
      paths:['哪些数据需要持久化(模块名.属性名)']
    })
  ]

*/
import Vuex from 'vuex'
import Vue from 'vue'
import cart from './modules/cart.js'
import user from './modules/user.js'
import persistedstate from 'vuex-persistedstate'
Vue.use(Vuex)
const store = new Vuex.Store({
  state: {},
  mutations: {},
  actions: {},
  getters: {},
  modules: {
    cart,
    user
  },
  plugins: [
    persistedstate({
      // key: 'vuex',
      paths: ['cart.num', 'cart.cart', 'user.address', 'user.token', 'user.userInfo'],
      storage: {
        getItem: (key) => {
          return uni.getStorageSync(key)
        },
        setItem: (key, value) => {
          uni.setStorageSync(key, value)
        },
        removeItem: (key) => {
          uni.removeStorageSync(key)
        }
      }
    })
  ]
})
export default store